<!--
 * @Author: HeAo
 * @Date: 2021-09-29 09:25:04
 * @LastEditTime: 2021-09-29 09:32:38
 * @LastEditors: HeAo
 * @Description: 
 * @FilePath: \web2103-2105\web2103code\3-1-ES6\day05\2-promise-ajax.html
 * 别乱动！
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="./jquery.js"></script>
  <script>
    window.onload = function () {
      const baseURL = 'http://47.94.46.113:8888'
      const promise = new Promise(function (resolve, reject) {
        $.ajax({
          url: baseURL + '/index/category/findAll',
          method: 'post',
          success(res) {
            // 异步请求成功，调用resolve
            resolve(res)
          },
          error(res) {
            // 异步请求失败，调用reject
            reject(res)
          }
        })
      })

      promise.then((res) => {
        console.log(res);
      }).catch((err) => {
        console.log(err);
      })
    }
  </script>
</head>

<body>

</body>

</html>